<template>
    <div>
        <v-header></v-header>
        <div class="dis10"></div>
        <div class="listbox aps8">
            <el-form
                    :model="ruleForm"
                    status-icon
                    :rules="rules"
                    ref="ruleForm"
                    label-width="100px"
                    class="demo-ruleForm"
            >
                <el-form-item label="输入密码" prop="password">
                    <el-input type="password" v-model="ruleForm.password" autocomplete="off" class="w300"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                    <!--<el-button @click="resetForm('ruleForm')">重置</el-button>-->
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
  // import cache from "@cache";
  export default {
    data() {
      // var validatePass = (rule, value, callback) => {
      //   if (value === "") {
      //     callback(new Error("请输入密码"));
      //   } else {
      //     if (this.ruleForm.cur_password !== "") {
      //       this.$refs.ruleForm.validateField("checkPass");
      //     }
      //     callback();
      //   }
      // };
      // var validatePass2 = (rule, value, callback) => {
      //   if (value === "") {
      //     callback(new Error("请再次输入密码"));
      //   } else if (value !== this.ruleForm.new_password) {
      //     callback(new Error("两次输入密码不一致!"));
      //   } else {
      //     callback();
      //   }
      // };
      return {
        ruleForm: {
          password: "",
          // new_password: "",
          // cur_password: ""
        },
        rules: {
          password: [
            { required: true, message: "请输入原密码", trigger: "blur" }
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        // let a = cache.get('token')
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.$api
                .get("set_master", {'password' :this.ruleForm.password})
                .then(res => {
                  if (res.status === 1) {
                    this.$success(res.msg);
                    this.$router.push({ path: "/snmpManage/collection/target" });
                  } else {
                    this.$error(res.msg);
                  }
                });
          } else {
            this.$error("请检查之后，确认无误再提交");
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  };
</script>

<style lang="scss" scoped>
    .listbox {
        margin-top: 40px;
    }
</style>>